;(function ($,window,document,undefined){
	
	CP.ChooseProduct = function (){

		var _this = this;
		var html = '<div id="{0}"" class="{1}" style="margin-bottom: 10px;"></div>';

		this.$el = null;
		this.productService = null;
		this.data = null;

		this.init = function () {
			console.log('LEFT INIT');
			html = html.format(MYLIB.constant.choose_product_id,MYLIB.constant.choose_product_class);
			this.$el = $(html);

			this.productService = new CP.productSerice();

			this.renderProduct();
		}

		this.getElement = function () {
			return this.$el;
		}

	};

	CP.ChooseProduct.prototype.productDicts = [];

	CP.ChooseProduct.prototype.renderProduct = function () {
		var _this = this;

		var ajaxResult = this.productService.getProducts(4);
		MYLIB.LOADING_LITTLE(_this.$el,'loading..');
		ajaxResult.done(function(data) {
			console.log(data);

			_this.data = data.products;
			
			_this.render(_this.data);

			MYLIB.REMOVE_LOADING_LITTLE(_this.$el);

		})

	}

	CP.ChooseProduct.prototype.render = function (data) {
		var _this = this;

		_.each(data, function(value, key, list){
		
			var item = new CP.ProductItem();

			item.init(value);

			_this.$el.append(item.getElement());
		
		});

	}

})(jQuery,window,document)